import new.targetCompletionCalculation as tcc
import new.get_personal_completion as gpc
import new.fill_excel as fe
import new.fill_excel as te
import new.sorce as s
import new.convert2object as co
import new.analyze as analyze
import new.picture as picture
import json


def big_function():
    
    tree = json.load(open('tree.json'))
    #得到目标对应表
    title = '2018-2019第二学期 钢结构设计原理 试卷分析表'
    class_info = '课程：[CE30108]钢结构设计原理（建工、地下、安装方向）        上课班级：208211-002              任课教师：熊刚'
    corr_list = co.readList2(tree)
    topic_list = co.readList1(tree)
    topic_full_grades = co.regretGrades(tree)
    small_target_value = co.getSmallTargetValue(topic_full_grades, corr_list)
    wb = co.makeExcelTitle(title,class_info,topic_list,topic_full_grades,corr_list, small_target_value)
    wb.save('excel_output/目标对应表.xls')

    # 得到成绩分析表
    title='2018-2019第二学期 钢结构设计原理 试卷分析表'
    class_info='课程：[CE30108]钢结构设计原理（建工、地下、安装方向）        上课班级：208211-002              任课教师：熊刚'
    topic_list = analyze.readList1(tree)
    corr_list = analyze.readList2(tree)
    regret_full_grades = analyze.regretGrades(tree)
    small_target_value = analyze.getSmallTargetValue(regret_full_grades,corr_list)
    wb,ws = analyze.makeExcelTitle(title,class_info,topic_list,regret_full_grades,small_target_value)
    # wb.save('成绩分析表.xls')

    usual = json.load(open('usual_performance.json'))
    test = json.load(open('test_score.json'))
    target_value = json.load(open('tv.json'))
    print(usual)
    print(test)

    ut = target_value[0]
    tt = target_value[1]
    ws0 = ws[0]
    ws1 = ws[1]
    
    # dao.xls为模板，没有意义
    s.anaysis('tmp/grade.xls','excel_output/成绩分析表.xls', usual, ut, wb, ws0)
    s.anaysis('tmp/grade.xls','excel_output/成绩分析表.xls', test, tt, wb, ws1)

    # 得到各班教学评价表
    # stpe1 得到表头
    title='2018-2019第二学期 钢结构设计原理 目标达成度计算表'
    class_info='  课程：[CE30108]钢结构设计原理（建工、地下、安装方向）        上课班级：208211-002              任课教师：熊刚'
    # m就是c总返回的列表
    corr_list = tcc.readList(tree)[0]
    weight = tcc.readList(tree)[1]
    regret_full_grades = tcc.regretGrades(tree)
    small_target_value = tcc.getSmallTargetValue(regret_full_grades,corr_list)
    wb,ws = tcc.makeExcelTitle(title,class_info,small_target_value,weight)
    save_path = 'excel_output/header/目标达成度计算表.xls'
    wb.save(save_path)

    # step2 得到数据
    df = gpc.getStudentInfo('excel_output/成绩分析表.xls', small_target_value)
 
    # step3 生成excel

    a = te.fill_excel(wb, ws, df, 'excel_output/各班教学评价表.xls','excel_output/header/目标达成度计算表.xls')

    '''
    存数据库
    '''
    # 绘图
    pd_data, completion_list = picture.get_data('excel_output/各班教学评价表.xls', sheel_name='各教学班评价表')

    describe_info = picture.getDescribeInfo(pd_data, completion_list=completion_list)

    target_list = ['课程目标1', '课程目标2', '课程目标3', '课程目标4', '总目标']
    rank_list = ['0-0.59', '0.60-0.69', '0.7-0.79', '0.8-0.89', '0.9-1']

    picture.drawDescibe(describe_info, target_list, rank_list)

    # 输出的excel表位置，注意只能输出xls格式
    save_path = 'excel_output/绘图表.xls'
    picture.creatXLS(describe_info, save_path, target_list)

# def merge():
#     pass

# big_function()
# merge()


